#pragma once

#include <AVUIControl.h>

namespace AVUI {

class DataTemplate;
class DataTemplateSelector;

class ContentControl : public Control
{
    friend class ItemsControl;

public:
    ContentControl() : m_contentIsNotLogical(false), m_contentIsItem(false) { };
    ~ContentControl() { };

    DECLARE_ELEMENT(ContentControl, Control);

    DECLARE_DEPENDENCY_PROPERTY_BEGIN(Content);
        DECLARE_ATTRIBUTE_CONTENTPROPERTY();
    DECLARE_DEPENDENCY_PROPERTY_END();
    TRefCountedPtr<Object> get_Content() { return GetValue(get_ContentProperty()); }
    void set_Content(Object* pValue) { return SetValue(get_ContentProperty(), pValue); }

    DECLARE_READONLY_DEPENDENCY_PROPERTY(HasContent);
    bool get_HasContent() { return AVUI::UnboxValue<bool>(GetValue(get_HasContentProperty())); }

    DECLARE_DEPENDENCY_PROPERTY(ContentTemplate);
    TRefCountedPtr<DataTemplate> get_ContentTemplate() { return (DataTemplate*)(Object*)GetValue(get_ContentTemplateProperty()); }
    void set_ContentTemplate(DataTemplate* pValue) { SetValue(get_ContentTemplateProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(ContentTemplateSelector);
    TRefCountedPtr<DataTemplateSelector> get_ContentTemplateSelector() { return (DataTemplateSelector*)(Object*)GetValue(get_ContentTemplateSelectorProperty()); }
    void set_ContentTemplateSelector(DataTemplateSelector* pValue) { SetValue(get_ContentTemplateSelectorProperty(), (Object*)pValue); } 

protected:

    bool get_ContentIsItem() { return m_contentIsItem; }
    void set_ContentIsItem(bool contentIsItem) { m_contentIsItem = contentIsItem; }

    bool get_ContentIsNotLogical() { return m_contentIsNotLogical; }
    void set_ContentIsNotLogical(bool contentIsNotLogical) { m_contentIsNotLogical = contentIsNotLogical; }

    virtual void OnContentChanged(Object* pOldContent, Object* pNewContent);

    virtual TRefCountedPtr<Object> get_LogicalChildren();

private:
    static void StaticConstructor();

    void PrepareContentControl(Object* pItem, DataTemplate* pItemTemplate, DataTemplateSelector* pItemTemplateSelector);
    static void OnContentChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);


    bool m_contentIsNotLogical;
    bool m_contentIsItem;
};

 


}; // namespace AVUI

